package com.itheiam62;
/**
 * @author Administrator
 * @创建时间 2015-7-11 下午4:37:46
 * @描述 TODO
 *
 * @ svn提交者：$Author$
 * @ 提交时间: $Date$
 * @ 当前版本: $Rev$
 */
public class MyQueue
{

	private Object datas[];
	private int pushIndex;//入队的下标
	private int popIndex; //出队的下标
	private int counts;//记录数据的个数
	
	public MyQueue(int size){
		datas = new Object[size];
	}
	public MyQueue(){
		this(10);
	}
	
	public boolean isEmpty(){
		return counts == 0;
	}
	public String toString(){
		StringBuilder mess = new StringBuilder();
		for (int i = popIndex; i <= counts; i++) {
			mess.append(datas[i % datas.length] + ",");
		}
		return mess + "";
	}
	
	public boolean isFull(){
		return counts == datas.length;
	}
	
	/**
	 * 入队列
	 * @param data
	 */
	public void push(Object data) {
		if (isFull()) {
			return;
		}
		datas[pushIndex++ % datas.length] = data;
		counts++;
	}
	
	public Object popup(){
		Object data = datas[popIndex++ % datas.length];
		counts--;
		return data;
	}
	
	

}
